package com.itheima.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.service.ReportMemberService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = ReportMemberService.class,protocol = "dubbo")
@Transactional
public class ReportMemberServiceImp implements ReportMemberService {
    @Autowired
    private MemberDao reportMemberDao;

    @Override
    public List<String> findOneYealTime(String time) {
        return reportMemberDao.findOneYealTime(time);
    }

    @Override
    public int findCountBYTime(String date) {
        date=date+"%";
        return reportMemberDao.findCountBYTime(date);
    }
     //获取套餐所有姓名
    @Override
    public List<String> getSetmealReport() {
        return reportMemberDao.getSetmealReport();
    }

    @Override
    public List<Map<String, Object>> findNameAndNumber() {
        List<Map<String, Object>> list = new ArrayList<>();
        HashMap<String, Object> map = new HashMap<>();
        //获取套餐姓名
//        List<String> setmealReport = reportMemberDao.getSetmealReport();
//        for (String setmealName : setmealReport) {
//            // //获取套餐被预约的人数
////            int count = reportMemberDao.findCountByName(setmealName);
//            map.put(setmealName,count);
//        }
        List<Map<String, Object>> countByName = reportMemberDao.findCountByName();
//        list.add(map);
        return countByName;
    }

    /**
     *  获得运营统计数据 * Map数据格式：
     *  * todayNewMember ‐> number  今天新注册会员
     *  * totalMember ‐> number   所有注册数总记录
     *  * thisWeekNewMember ‐> number   这周注册人数
     *  * thisMonthNewMember ‐> number  月注册人数
     *  *todayOrderNumber ‐> number    今天新预约人数
     *  * todayVisitsNumber ‐> number  今天到诊数
     *  * thisWeekOrderNumber ‐> number  一周预约人数总记录
     *  * thisWeekVisitsNumber ‐> number  这周到诊人数
     *  * thisMonthOrderNumber ‐> number  一月预约人数总记录
     *  * thisMonthVisitsNumber ‐> number  一月到诊人数总记录
     *  * hotSetmeals ‐> List<Setmeal>  热门的套餐
     */
    @Override
    public Map getBusinessReportData() throws Exception {
        //获取今天日期
        String today = DateUtils.parseDate2String(new Date(),"YYYY-MM-dd");
        //获取本周第一天的时间
        String mondayWeek = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月第一天的时间
        String firdayMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
       //获取今天新注册的会员
        int newCount = reportMemberDao.findTodayNewVip(today);
        //查询本周注册的会员数
        int thisWeekNew = reportMemberDao.findWeekVipFindByTime(mondayWeek);
        //查询本月注册的会员数
        int thisMonthNew = reportMemberDao.findMonthVipFindByTime(firdayMonth);
        //查询总注册会员数
        int allCount = reportMemberDao.findAllVip();
        //查看今日到诊数量
        int todayVisitsNumber = reportMemberDao.findTodayVisitsNum(today);
        //查看本周一到当前的到诊数量
        int thisWeekVisitsNumber = reportMemberDao.findThisWeekVisitsNum(mondayWeek);
        //查看本月第一天到当前的诊数量
        int thisMonthVisitsNumber = reportMemberDao.findThisMonthVisitsNum(firdayMonth);
        //查询今天预约的人数
        int todayOrderNum = reportMemberDao.findOrderByThisToday(today);
        //查询本周预约的人数
        int weekOrderNum = reportMemberDao.findOrderByThisWeek(mondayWeek);
        //查询今天预约的人数
        int monthOrderNum = reportMemberDao.findOrderByThisMonth(firdayMonth);
        //查看预约热门套餐(预约人数最多)前四条
        List<Map> hosL = reportMemberDao.findHotSetmeal();

        //创建一个map集合进行封装
        HashMap<String, Object> map = new HashMap<>();
        map.put("reportData",today);
        map.put("todayNewMember",newCount);
        map.put("totalMember",allCount);
        map.put("thisWeekNewMember",thisWeekNew);
        map.put("thisMonthNewMember",thisMonthNew);
        map.put("todayOrderNumber",todayOrderNum);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",weekOrderNum);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisWeekVisitsNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hosL);
        return map;
    }

}
